package MediaOnline.WebService;

import java.util.ArrayList;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import MediaOnline.Data.ThongTinDienVien;
import MediaOnline.Data.userData;
import MediaOnline.Data.videoData;
import MediaOnline.GUI.Nahi_MediaActivity;
import MediaOnline.GUI.actActorInfo;
import MediaOnline.GUI.actFilmDetailInfo2;
import MediaOnline.GUI.actListFilm;
import MediaOnline.General.paramConst;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;

public class SessionRegister {
/** Called when the activity is first created. */
    
	private static final String Soap_MethodName = "AndroidSetSession";
	private static final String Soap_Action = paramConst.Webservice_NameSpace+Soap_MethodName;
	private static final String Soap_NameSpace = paramConst.Webservice_NameSpace;
	private static final String Soap_URL = paramConst.Webservice_Url+"FilmService.asmx?op="+Soap_MethodName;
	public Context mContext;
	public ArrayList<String> arrUser;
	public SoapObject request, request2;
	public SoapSerializationEnvelope Soap_Evelope;
	public ArrayAdapter<String> adpUser;
	
	public boolean isOnline=false;
	//ProgressDialog progress; 
		public SessionRegister(Context ctx, String url){
			mContext = ctx;
			request = new SoapObject(Soap_NameSpace, Soap_MethodName);
			Soap_Evelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
	        //Soap_Evelope.addMapping(Soap_NameSpace, "actViewAllUser", this.getClass());
	        Soap_Evelope.dotNet=true;
	        request.addProperty("user",userData.Username);
	        request.addProperty("dUrl",url);
	        request.addProperty("key",videoData.MAIN_KEY);
	        
	        Log.d("session  user/key/dUrl:::", userData.Username+"/"+videoData.MAIN_KEY+"/"+url);
	        
	        Soap_Evelope.setOutputSoapObject(request);
		}
		
		public void reg(){
			Register g = new Register();
	      	g.execute();
        }

	class Register extends AsyncTask<String, Void, String> {

		@Override
		protected void onPostExecute(String result) {
			// TODO Auto-generated method stub
			Intent intent = new Intent(mContext, Nahi_MediaActivity.class);
			Bundle newBundle = new Bundle();
			newBundle.putString("Link",paramConst.URL_XEM_PHIM+"?u="+userData.Username);
			Log.d("session Bundle link:::	", paramConst.URL_XEM_PHIM+"?u="+userData.Username);
			intent.putExtras(newBundle);
			mContext.startActivity(intent);
		}

		@Override
		protected void onPreExecute() {
			// TODO Auto-generated method stub
		}

		@Override
		protected void onProgressUpdate(Void... values) {
			// TODO Auto-generated method stub
			
		}


		@Override
		protected String doInBackground(String... params) {
			// TODO Auto-generated method stub
			Log.d("session Asynctask ::: ", "Background");
	        HttpTransportSE androidHttpTransport = new HttpTransportSE(Soap_URL);
	        
	     	//CallService
	      	try{
	      		androidHttpTransport.call(Soap_Action, Soap_Evelope);
	            //Lay du lieu file xml
	      		SoapObject requestall=(SoapObject) Soap_Evelope.getResponse();
	      		if (requestall==null) {
	      			Log.d("session request all::::", "null");
				}
	      		else {
	      			Log.d("session request all::::", requestall.toString());
				}
	      		
			}
			catch(Exception e){
				Log.d("session Asynctask exception ::: ", e.toString());

			}
	      	Log.d("session Asynctask ::: ", "Done Background");
			return null;
		}
		
	}
}
